package com.jiangyao.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.jiangyao.model.entity.JobData;
import com.jiangyao.dao.IJobDataDao;
import com.jiangyao.service.JobDataService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 职位数据 服务实现类
 * </p>
 *
 * @author xiangyan
 * @since 2020-09-02
 */
@Service
public class JobDataServiceImpl extends ServiceImpl<IJobDataDao, JobData> implements JobDataService {
    @Autowired
    IJobDataDao jobDataDao;
    @Override
    public Boolean addViewNum(Integer jobId) {
        QueryWrapper<JobData> params = new QueryWrapper<>();
        params.eq("job_id",jobId).last("limit 1");
        JobData obj = jobDataDao.selectOne(params);
        if(obj==null){
            JobData info = new  JobData();
            info.setJobId(jobId);
            info.setCollectNum(0);
            info.setLikeNum(0);
            info.setViewNum(0);
            this.save(info);
        }
        return jobDataDao.addViewNum(jobId);
    }

    @Override
    public Boolean updateCollectNum(Integer jobId) {
        QueryWrapper<JobData> params = new QueryWrapper<>();
        params.eq("job_id",jobId).last("limit 1");
        JobData obj = jobDataDao.selectOne(params);
        if(obj==null){
            JobData info = new  JobData();
            info.setJobId(jobId);
            info.setCollectNum(0);
            info.setLikeNum(0);
            info.setViewNum(0);
            this.save(info);
        }
        return jobDataDao.updateCollectNum(jobId);
    }
}
